using System.Diagnostics;
using System.IO;
using Microsoft.Practices.RecipeFramework;
using VSSDKAssist.Assets.Actions.Base;
using VSSDKAssist.Assets.Actions.General;
using EnvDTE;

namespace VSShellAssist.Recipes.TestSplashScreen
{
    /// <summary>
    /// Action thats tests a VS splash screen
    /// </summary>
    public class TestSplashScreenAction : ActionBase
    {
        #region Constants
        private const string ExeExtension = ".exe";
        #endregion

        [Input(Required = true)]
        public Project Project { get; set; }

        /// <summary>
        /// Called when [execute].
        /// </summary>
        protected override void OnExecute()
        {
            string outputPath = this.Project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString();
            string exeName = string.Concat(this.Project.Name, ExeExtension);
            string vsShellApplicationPath = Path.Combine(outputPath, exeName);

            if(File.Exists(vsShellApplicationPath))
            {
                using(ExecuteProcessAction executeProcessAction = new ExecuteProcessAction())
                {
                    executeProcessAction.Site = this.Site;
                    executeProcessAction.FileName = vsShellApplicationPath;
                    executeProcessAction.Arguments = @"/Splash";
                    executeProcessAction.CreateWindow = true;
                    executeProcessAction.WindowStyle = ProcessWindowStyle.Maximized;
                    executeProcessAction.WaitForExit = false;
                    executeProcessAction.Execute();
                }
            }
        }
    }
}